<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>个人页面</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css">
    <link rel="stylesheet" href="/css/userProfiles.css">
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>
    <script src="/js/plugins/jquery-form/jquery.form.js"></script>

    <script>
        $(function () {
            //获取url上的id值
            var params = getParams();
            console.log(params.id);
            //获取当前登录用户
            var user = JSON.parse(sessionStorage.getItem("user"));
            console.log(user);
            //跳转到私信列表
            $("#letterBtn").click(function () {
                location.href="/mine/chatTime.html";
            })
            if(params.id){
                //个人页面评论人信息
                $.get("/users/"+params.id,function (data) {
                    $(".info").renderValues(data);
                })

                //自己不能关注或私信自己
                if(user.id==params.id){
                    $("#followBtn").attr("style","display: none")
                    $("#letterBtn").attr("style","display: none")
                }

                //粉丝数
                $.get("/attentions/"+params.id+"/fans",function (data) {
                    $("#fans").html(data);
                })
                //关注数
                $.get("/attentions/"+params.id+"/attentionNum",function (data) {
                    console.log(data);
                    $("#attentionNum").html(data);
                })

                var index;//粉丝数变量
                //个人页面关注
                $.get("/attentions",{currentUserId:user.id,attentionUserId:params.id},function (data) {
                    console.log(data.id);
                    if (data.state==true) {
                        $("#followBtn").html("取消关注");
                        $("#followBtn").css("background-color","red");
                        $("#followBtn").css("border-color","red");
                        index=true;
                    }else {
                        $("#followBtn").html("关注");
                        $("#followBtn").css("background-color","green");
                        $("#followBtn").css("border-color","green");
                        index=false;
                    }

                    $("#followBtn").click(function () {
                        if(index==true){
                            $.get("/attentions",{currentUserId:user.id,attentionUserId:params.id},function (data) {
                                $.ajax({
                                    type:'DELETE',
                                    url:'/attentions',
                                    data:{aid:data.id},
                                    success:function (data) {
                                        $("#followBtn").html("关注");
                                        $("#followBtn").css("background-color", "green");
                                        $("#followBtn").css("border-color", "green");

                                        index=false;

                                        //粉丝数
                                        $.get("/attentions/"+params.id+"/fans",function (data) {
                                            if(data>0){
                                                $("#fans").html(data-1);
                                            }else {
                                                $("#fans").html(0);
                                            }
                                        })
                                    }
                                })
                            })
                        }else {
                            $("#currentUserId").val(user.id);
                            $("#attentionUserId").val(params.id);
                            $("#attentionForm").ajaxSubmit(function (data) {
                                if(data.success){
                                    $("#followBtn").html("取消关注");
                                    $("#followBtn").css("background-color","red");
                                    $("#followBtn").css("border-color","red");

                                    index=true;

                                    //粉丝数
                                    $.get("/attentions/"+params.id+"/fans",function (data) {
                                        $("#fans").html(data);
                                    })
                                }

                            });
                        }
                    })
                })


                //个人页面他的游记
                $.get("/users/"+params.id+"/travels",{state:3},function (data) {
                    $("#travels-tab span").html(data.size);
                    $("#travels").renderValues(data,{
                        'setTravelHref':setHref
                    })
                })

                //个人页面他的点评
                $.get("/users/strategyComment",{userId:params.id},function (data) {
                    //点评条数显示
                    $("#comments-tab span").html(data.size);

                    //渲染他的点评
                    $("#comments").renderValues(data,{
                        'setHref':setHref,
                        'setCatalogHref':setHref
                    });

                    var html='';//用于临时拼接评论图片
                    var starNums='';//用于临时拼接星星
                    var num;//星星个数
                    var starSolid='<i class="fa fa-star"></i>';//实心星星
                    var starHollow='<i class="fa fa-star-o"></i>';//空心星星

                    $.each(data.list,function (index, ele) {
                        //console.log((ele.imgUrls).split(";"));

                        //实心数
                        starSolid='';
                        for(var i=0; i<ele.starNum; i++){
                            starSolid+='<i class="fa fa-star"></i>';
                        }

                        //空心数
                        starHollow='';
                        for(var j=0; j<5-ele.starNum; j++){
                            starHollow+='<i class="fa fa-star-o"></i>';
                        }


                        //图片地址切割
                        var arr=(ele.imgUrls).split(";");
                        //循环拼接图片
                        $.each(arr,function (index1,ele1) {
                            if(index1<arr.length-1){
                                html+='<li><img src="'+ele1+'"></li>';
                            }
                        })

                    })
                    $(".comment-img").append(html);//将图片设置回去
                    starNums=starSolid+starHollow;
                    $(".comment-star").html(starNums);//
                })
            }
        })
    </script>
</head>
<body>
<div class="container bg" style="background-image: url(/img/user/bg/bg6.jpeg);">
    <a href="javascript:window.history.go(-1)" class="my-arrow">
        <span><i class="fa fa-chevron-left fa-2x"></i></span>
    </a>
    <div class="container">
        <div class="info">
            <img class="rounded-circle" width="17%" render-src="headImgUrl">
            <p class="name" render-html="nickName">奋斗的小蜜蜂</p>
            <p render-html="sign">一直奋斗的小蜜蜂</p>

            <div class="row num">
                <div class="col-2 border border-left-0 border-top-0 border-bottom-0">
                    <div>
                        <span id="attentionNum">1</span>
                    </div>
                    <div>
                        <span>关注</span>
                    </div>
                </div>
                <div class="col-2">
                    <div>
                        <span id="fans">0</span>
                    </div>
                    <div>
                        <span>粉丝</span>
                    </div>
                </div>
                <form id="attentionForm" action="/attentions" method="post">
                    <input type="hidden" name="id">
                    <input type="hidden" name="currentUser.id" id="currentUserId">
                    <input type="hidden" name="attentionUser.id" id="attentionUserId">
                </form>
                <div class="col">
                    <button type="button" class="btn btn-outline-light ibtn" id="letterBtn">私信</button>
                    <button type="button" class="btn btn-success ibtn" id="followBtn">关注</button>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="tabs">
    <ul class="nav nav-pills nav-justified  border border-left-0 border-top-0 border-right-0" id="pills-tab"
        role="tablist">
        <li class="nav-item">
            <a class="nav-link active" id="travels-tab" data-toggle="pill" href="#travels">
                TA的游记[<span>1</span>]
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link " id="comments-tab" data-toggle="pill" href="#comments">
                TA的点评[<span>1</span>]
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" id="pills-contact-tab" data-toggle="pill" href="#pills-contact">
                TA的旅行单[<span>0</span>]
            </a>
        </li>
    </ul>
    <div class="container tab-content" id="pills-tabContent">
        <div class="tab-pane fade show active" id="travels">

            <dl class="list">
                <dd render-loop="list">
                    <a href="/travelContent.html?id=" render-fun="setTravelHref" render-key="list.id">
                        <img render-src="list.coverUrl">
                        <p><span class="title" render-html="list.title">入住长隆熊猫酒店，天天都是儿童节</span>
                            <span class="span-right">
						 				<span>0</span> <i class="fa fa-thumbs-o-up"></i></span>
                        </p>
                    </a>
                    <hr>
                </dd>
            </dl>

        </div>

        <div class="comment tab-pane fade " id="comments">
            <input type="hidden" name="currentPage" value="1">
            <input type="hidden" name="pageSize" value="5">
            <input type="hidden" name="rows" value="1">
            <div render-loop="list">
                <div class="row">
                    <div class="col-2 comment-head">
                        <img class="rounded-circle" render-src="list.user.headImgUrl">
                    </div>
                    <div class="col">
                        <span class="comment-star"><i class="fa fa-star"></i><i class="fa fa-star"></i><i
                                class="fa fa-star"></i><i class="fa fa-star-o"></i><i class="fa fa-star-o"></i></span>

                        <span class="comment-date" render-html="list.createTime">2018-07-11</span>
                        <div class="comment-content">
                            <a href="strategyComment.html?id=" render-key="list.id" render-fun="setHref">
                                <p render-html="list.content">骑了个单车到沙面，春风把从上下九和宝华路带来的燥热吹散。沙面临江，下午的时光让这富有异国风情的公园显得更加宁静惬意，哪怕...</p>
                            </a>
                        </div>
                        <ul class="comment-img">
                        </ul>

                        <div class="comment-link">
                            <a href="/strategyCatalogs.html?id=" render-fun="setCatalogHref" render-key="list.strategy.id">
                                <img render-src="list.strategy.coverUrl"> <span render-html="list.strategy.title">广州攻略</span>
                                <i class="fa fa-angle-right fa-2x"></i>
                            </a>
                        </div>

                    </div>
                </div>
            </div>

        </div>
        <div class="tab-pane fade" id="pills-contact">.3333..</div>
    </div>
</div>


</body>
</html>